import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../resources.dart';

/// created by hcl
/// on 2024/4/13
/// DialogTextField
/// desc
class DialogYesNoColor {
  static show(
      {String title = "",
      String content = "",
      String cancelText = "",
      String confirmText = "",
      VoidCallback? cancelFunc,
      VoidCallback? confirmFunc,
      bool showCancel = true,
      bool dismissible = false}) {
    Toast.showDialogWidget(
        child: _DialogYesNoColor(
            title: title,
            content: content,
            cancelText: cancelText,
            confirmText: confirmText,
            cancelFunc: cancelFunc,
            confirmFunc: confirmFunc,
            showCancel: showCancel),
        dismissible: dismissible);
  }
}

class _DialogYesNoColor extends StatefulWidget {
  String title = "";
  String content = "";
  String cancelText = "";
  String confirmText = "";
  VoidCallback? cancelFunc;
  VoidCallback? confirmFunc;
  bool showCancel = true;

  _DialogYesNoColor(
      {this.title = "",
      this.content = "",
      this.cancelText = "",
      this.confirmText = "",
      this.cancelFunc,
      this.confirmFunc,
      this.showCancel = true});

  @override
  State<StatefulWidget> createState() => _DialogYesNoColorState();
}

class _DialogYesNoColorState extends State<_DialogYesNoColor> {
  FocusNode focusNode = FocusNode();
  TextEditingController editingController = TextEditingController();
  String? error;

  @override
  Widget build(BuildContext context) {
    if (widget.cancelText.isEmpty) {
      widget.cancelText = word.cancel;
    }
    if (widget.confirmText.isEmpty) {
      widget.confirmText = word.confirm;
    }
    return SizedBox(
      width: designWidth.ss,
      child: Container(
        margin: EdgeInsets.symmetric(horizontal: 30.ss),
        child: Card(
          elevation: 5,
          shadowColor: ColorUtils.app_color,
          child: Container(
            decoration: BoxDecoration(
              color: ColorUtils.color_F5F5F5,
              borderRadius: BorderRadius.all(Radius.circular(16.ss)),
            ),
            child: Column(
              children: [
                SizedBox(height: 10.ss),
                widget.title.isNotEmpty
                    ? Container(
                        alignment: Alignment.centerLeft,
                        padding: EdgeInsets.symmetric(horizontal: 16.ss),
                        child: Text(
                          widget.title,
                          style: medium316,
                          textAlign: TextAlign.start,
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                        ),
                      )
                    : const SizedBox.shrink(),
                Container(
                  constraints: BoxConstraints(minHeight: 70.ss),
                  alignment: Alignment.centerLeft,
                  padding: EdgeInsets.symmetric(horizontal: 16.ss),
                  child: Text(
                    widget.content,
                    style: normal714,
                    textAlign: TextAlign.center,
                  ),
                ),
                SizedBox(
                  height: 46.ss,
                  child: Row(
                    children: [
                      widget.showCancel
                          ? Expanded(
                              child: Center(
                              child: ElevatedButton(
                                onPressed: () {
                                  Nav.pop(result: backResult(NORMAL_CODE, ''));
                                  if (widget.cancelFunc != null) {
                                    widget.cancelFunc!();
                                  }
                                },
                                style: ElevatedButton.styleFrom(
                                    backgroundColor: ColorUtils.color_F5F5F5,
                                    maximumSize: Size(140.ss, 40.ss),
                                    minimumSize: Size(100.ss, 40.ss),
                                    padding: EdgeInsets.all(4.ss),
                                    shape: RoundedRectangleBorder(
                                        borderRadius:
                                            BorderRadius.circular(8.ss))),
                                child:
                                    Text(widget.cancelText, style: mediumAD15),
                              ),
                            ))
                          : const SizedBox(),
                      Expanded(
                          child: Center(
                        child: ElevatedButton(
                          onPressed: () {
                            Nav.pop(result: backResult(NORMAL_CODE, ''));
                            if (widget.confirmFunc != null) {
                              widget.confirmFunc!();
                            }
                          },
                          style: ElevatedButton.styleFrom(
                              backgroundColor: ColorUtils.app_color,
                              foregroundColor: Colors.transparent,
                              maximumSize: Size(140.ss, 40.ss),
                              minimumSize: Size(100.ss, 40.ss),
                              padding: EdgeInsets.all(4.ss),
                              shape: RoundedRectangleBorder(
                                  borderRadius: BorderRadius.circular(8.ss))),
                          child: Text(widget.confirmText, style: mediumF16),
                        ),
                      ))
                    ],
                  ),
                ),
                SizedBox(height: 16.ss),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
